package yxy.game.pm2.command.daliy;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.TaskMessage;
import yxy.game.pm2.module.daily.DailyHandle;

/** 任务成就 任务奖励领取 */
@MessageType(proto = Command.DailyTaskProgressBonusReceive, classtype = TaskMessage.DailyTaskProgressBonusReceiveRequest.class)
public class CMD_DailyTaskProgressBonusReceive extends Command<TaskMessage.DailyTaskProgressBonusReceiveRequest> {

	@Override
	public void execute(MessageSource messageSource, TaskMessage.DailyTaskProgressBonusReceiveRequest request) {
		String playerCode = messageSource.getTag();
		String code = request.getCode();

		TaskMessage.DailyTaskProgressBonusReceiveResponse.Builder response = TaskMessage.DailyTaskProgressBonusReceiveResponse.newBuilder();

		try {
			Result result = new DailyHandle().reward(playerCode, code, response);

			send(messageSource, response, result);
		} catch (Exception e) {
			send(messageSource, response, Result.ParamError);
		}
	}

	private void send(MessageSource messageSource, TaskMessage.DailyTaskProgressBonusReceiveResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}